package com.housekeeping.housekeeping.cleanerInformation.entity;/*
package com.housekeeping.housekeeping.cleanerInformation.entity;

import com.housekeeping.housekeeping.cleanerInformation.utils.DbManager;
import com.mysql.jdbc.Connection;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

*/
/**
 * @author hua
 * @version JDK1.8
 * @date 2021/1/18 20:34
 *//*

public class ImageDemo {
    // 将图片插入数据库
     public static void readImage2DB() throws SQLException {
                 String path = "D:/1.png";
                 Connection conn = null;
                 PreparedStatement ps = null;
                 FileInputStream in = null;
                 try {
                         in = ImageUtil.readImage(path);
                         conn = (Connection) DbManager.getConnection();
                         String sql = "insert into cleaner_information (head_portrait) values(?)";
                         ps = conn.prepareStatement(sql);
                         ps.setBinaryStream(1, in, in.available());
                         int count = ps.executeUpdate();
                         if (count > 0) {
                                 System.out.println("插入成功！");
                             } else {
                                 System.out.println("插入失败！");
                             }
                     } catch (Exception e) {
                         e.printStackTrace();
                     } finally {
                         DbManager.closeAll(conn,null);
                         if (null != ps) {
                                 try {
                                         ps.close();
                                     } catch (SQLException e) {
                                         e.printStackTrace();
                                     }
                             }
                     }

             }

             // 读取数据库中图片
             public static void readDB2Image() throws SQLException {
                 String targetPath = "D:/image/1.png";
                 Connection conn = null;
                 PreparedStatement ps = null;
                 ResultSet rs = null;
                 try {
                         conn = (Connection) DbManager.getConnection();
                         String sql = "select * from cleaner_information";
                         ps = conn.prepareStatement(sql);
                         //ps.setInt(1, 1);
                         rs = ps.executeQuery();
                         while (rs.next()) {
                                 InputStream in = rs.getBinaryStream("photo");
                                 ImageUtil.readBin2Image(in, targetPath);
                             }
                     } catch (Exception e) {
                         e.printStackTrace();
                     } finally {
                     DbManager.closeAll(conn,null);
                         if (rs != null) {
                                 try {
                                         rs.close();
                                     } catch (SQLException e) {
                                         e.printStackTrace();
                                     }
                             }
                         if (ps != null) {
                                 try {
                                         ps.close();
                                     } catch (SQLException e) {
                                         e.printStackTrace();
                                     }
                             }

                     }
             }
     //测试
             public static void main(String[] args) throws SQLException {
                 //readImage2DB();
                 readDB2Image();
             }
}
*/
